package com.sline.set;

import com.sline.bean.Person;

import java.util.HashSet;

public class Demo1_HashSet {
    public static void main(String[] args) {
        // demo1();
        HashSet<Person> hs = new HashSet<>();
        hs.add(new Person("张三", 23));
        hs.add(new Person("张三", 23));
        hs.add(new Person("张三", 23));
        hs.add(new Person("李四", 24));
        hs.add(new Person("李四", 24));
        hs.add(new Person("李四", 24));

        System.out.println(hs);
    }

    private static void demo1() {
        HashSet<String> hs = new HashSet<>();
        boolean b1 = hs.add("a");
        boolean b2 = hs.add("a");
        hs.add("b");
        hs.add("d");
        hs.add("c");

        System.out.println(b1);
        System.out.println(b2);
        System.out.println(hs);

        for (String s: hs) {
            System.out.println(s);              // 只要能用迭代器迭代的, 就可以使用增强for循环遍历
        }
    }
}
